# -*- coding: utf-8 -*-

# **************************************************************************
# desc : 客户运单宽表明细
#    Relation ：
#jms_dwd.dwd_wide_customer_detail_incre_dt << [
#    jms_dim.dim_lmdm_sys_network_manage,
#    jms_dim.dim_lmdm_sys_area,
#    jms_dim.dim_lmdm_sys_customer,
#    jms_dim.dim_lmdm_sys_abnormal_piece,
#    jms_dwd.dwd_oms_order_dt,
 #   jms_dwd.dwd_yl_oms_oms_waybill_incre_dt,
#    jms_dwd.dwd_barscan_taking_dt,
#    jms_dwd.dwd_barscan_warehousing_dt,
 #   jms_dwd.dwd_barscan_send_dt,
 #   jms_dwd.dwd_barscan_deliver_dt,
 #   jms_dwd.dwd_barscan_collect_dt,
 #   jms_dwd.dwd_barscan_sign_dt,
 #   jms_ods.registration_problem_piece,
 #   jms_ods.tab_reback_transfer_express,
 #   jms_ods.tab_end_piece,
 #   jms_ods.yl_oms_pick_bill
# ]
# **************************************************************************
#    modify by 鲁昆明 2022/4/18 新增脚本
# **************************************************************************

from datetime import timedelta
# from utils.operators.spark_sql_operator import SparkSqlOperator
from utils.operators.cluster_for_spark_sql_operator import SparkSqlOperator
from jms.dim import jms_dim__dim_lmdm_sys_network_manage
from jms.dim.dim_lmdm_sys_area import jms_dim__dim_lmdm_sys_area
from jms.dim.dim_lmdm_sys_customer import jms_dim__dim_lmdm_sys_customer
from jms.dim.dim_lmdm_sys_abnormal_piece import jms_dim__dim_lmdm_sys_abnormal_piece
from jms.dwd.oms.dwd_oms_order_dt import jms_dwd__dwd_oms_order_dt
from jms.dwd.oms.dwd_yl_oms_oms_waybill_incre_dt import jms_dwd__dwd_yl_oms_oms_waybill_incre_dt
from jms.dwd.tab.dwd_barscan_taking_dt import jms_dwd__dwd_barscan_taking_dt
from jms.dwd.tab.dwd_barscan_warehousing_dt import jms_dwd__dwd_barscan_warehousing_dt
from jms.dwd.tab.dwd_barscan_send_dt import jms_dwd__dwd_barscan_send_dt
from jms.dwd.tab.dwd_barscan_deliver_dt import jms_dwd__dwd_barscan_deliver_dt
from jms.dwd.tab.dwd_barscan_collect_dt import jms_dwd__dwd_barscan_collect_dt
from jms.dwd.tab.dwd_barscan_sign_dt import jms_dwd__dwd_barscan_sign_dt
from jms.ods.mysql.registration_problem_piece import jms_ods__registration_problem_piece
from jms.ods.tab.tab_reback_transfer_express import jms_ods__tab_reback_transfer_express
from jms.ods.tab.tab_end_piece import jms_ods__tab_end_piece
from jms.ods.oms.yl_oms_pick_bill import jms_ods__yl_oms_pick_bill


jms_dwd__dwd_wide_customer_detail_incre_dt = SparkSqlOperator(
    task_id='jms_dwd__dwd_wide_customer_detail_incre_dt',
    task_concurrency=1,
    pool_slots=10,
    master='yarn',
    email=['lukunming@jtexpress.com','yl_bigdata@yl-scm.com'],
    name='jms_dwd__dwd_wide_customer_detail_incre_dt_{{ execution_date | date_add(1) | cst_ds }}',
    sql='jms/dwd/dwd_wide_customer_detail_incre_dt/execute.hql',
    driver_cores=2,
    driver_memory='6g',
    executor_cores=4,
    executor_memory='10G',
    num_executors=50,  # spark.dynamicAllocation.enabled 为 True 时，num_executors 表示最少 Executor 数
    conf={'spark.dynamicAllocation.enabled': 'true',  # 动态资源开启
          'spark.shuffle.service.enabled': 'true',  # 动态资源 Shuffle 服务开启
          'spark.dynamicAllocation.maxExecutors': 100,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.cachedExecutorIdleTimeout': 60,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode': 'dynamic',  # 允许删改已存在的分区
          'spark.executor.memoryOverhead': '2G',  # 堆外内存
          'spark.sql.shuffle.partitions': 1000,
          },
    # hiveconf={'hive.exec.dynamic.partition': 'true',  # 动态分区
    #           'hive.exec.dynamic.partition.mode': 'nonstrict',
    #           'hive.exec.max.dynamic.partitions': 30,  # 每天生成 30 个分区
    #           'hive.exec.max.dynamic.partitions.pernode': 30,  # 每天生成 30 个分区
    #           },
    yarn_queue='pro',
    execution_timeout=timedelta(hours=1)
)

jms_dwd__dwd_wide_customer_detail_incre_dt << [
    jms_dim__dim_lmdm_sys_network_manage,
    jms_dim__dim_lmdm_sys_area,
    jms_dim__dim_lmdm_sys_customer,
    jms_dim__dim_lmdm_sys_abnormal_piece,
    jms_dwd__dwd_oms_order_dt,
    jms_dwd__dwd_yl_oms_oms_waybill_incre_dt,
    jms_dwd__dwd_barscan_taking_dt,
    jms_dwd__dwd_barscan_warehousing_dt,
    jms_dwd__dwd_barscan_send_dt,
    jms_dwd__dwd_barscan_deliver_dt,
    jms_dwd__dwd_barscan_collect_dt,
    jms_dwd__dwd_barscan_sign_dt,
    jms_ods__registration_problem_piece,
    jms_ods__tab_reback_transfer_express,
    jms_ods__tab_end_piece,
    jms_ods__yl_oms_pick_bill
]
